﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace WiseLink.Infrastructure.Common
{
    public static class LogHelp
    {
        public static void Log(string category,string message)
        {
            Logger.Write(
                        new LogEntry
                        {
                            Categories = new[] { category },
                            Message = message
                        });
        }

        public static void Log(string category,Dictionary<string, object> extProperties, string message)
        {
            Logger.Write(
                        new LogEntry
                        {
                            Categories = new[] { category },
                            ExtendedProperties = extProperties,
                            Message = message
                        });
        }
        public static void Log(string category, Exception ex)
        {
            Log(category, string.Format("[Exception:]{0} \t [Stack:] {1}",  ex.Message, ex.StackTrace ?? ""));
            
            if (ex.InnerException != null)
            {
                Log(category, string.Format("[Inner Exception:]{0} \t [Stack:] {1}", ex.InnerException.Message, ex.InnerException.StackTrace ?? ""));
            }
        }
        public static void FlushLog()
        {
            Logger.Reset();
        }

    }
}
